# This code is part of the MWP System
# Copyright (c) 2012 Benjamin Lubin (blubin@bu.com) 
# Published under and subject to the GPLv2 license available at http://www.gnu.org/licenses/gpl-2.0.html

'''
Created on Dec 13, 2012
@author: blubin
'''

from backend.backend import Backend;
from workflow.task import Task;
from workflow.result import Result;
from workflow.flowData import Status;
from unique import UNIQUE;

class Dropzonebackend(Backend):
   
    def __init__(self): 
        Backend.__init__(self, "Dropzone"+UNIQUE, dashboard=True);

    def wire(self):
        self.register_result_listener("Reception", "Manifest", self.jumper_arrival_complete)
        self.register_result_listener("Billing", "Bill", self.billing_complete)
        self.register_result_listener("Instructor", "Teach", self.instructor_complete)
        self.register_result_listener("Pilot", "Verify", self.pilot_complete)
        self.register_result_listener("Checkout", "Video", self.checkout_complete)
    
    def jumper_arrival_complete(self, results):
        for result in results:
            task = Task.construct_from_result(result, "Billing", "Bill");
            self.workflow.add(task);
            self.workflow.update_status(result, Status.COMPLETE);

    def billing_complete(self, results):
        for result in results:
            task = Task.construct_from_result(result, "Instructor", "Teach");
            self.workflow.add(task);
            self.workflow.update_status(result, Status.COMPLETE);

    def instructor_complete(self, results):
        for result in results:
            task = Task.construct_from_result(result, "Pilot", "Verify");
            self.workflow.add(task);
            self.workflow.update_status(result, Status.COMPLETE);

    def pilot_complete(self, results):
        for result in results:
            task = Task.construct_from_result(result, "Checkout", "Video");
            self.workflow.add(task);
            self.workflow.update_status(result, Status.COMPLETE);

    def checkout_complete(self, results):
        for result in results:
            self.workflow.update_status(result, Status.COMPLETE)

if __name__ == '__main__':
    backend = Dropzonebackend();